﻿@using Covenant.Models.Covenant
@model CapturedCredential
@{
    Layout = "_Layout";
}

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3">
    <h1 class="h2">Create Credential</h1>
</div>

<form asp-controller="Credential" asp-action="CreatePasswordCredential">
    <input asp-for="Id" value="@Model.Id" class="form-control" type="hidden">
    <div class="form-row">
        <div class="form-group">
            <label asp-for="Type"></label><br/>
            <select asp-for="Type" asp-items="Html.GetEnumSelectList<CredentialType>()" class="selectpicker show-menu-arrow" data-dropup-auto="false" data-width="auto"></select>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group col-md-6">
            <label asp-for="Domain"></label>
            <input asp-for="Domain" class="form-control">
        </div>
        <div class="form-group col-md-6">
            <label asp-for="Username"></label>
            <input asp-for="Username" class="form-control">
        </div>
    </div>
    <div id="password-section">
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="Password">Password</label>
                <input id="Password" name="Password" class="form-control">
            </div>
        </div>
    </div>
    <div id="hash-section" hidden>
        <div class="form-row">
            <div class="form-group col-md-3">
                <label for="HashCredentialType">HashCredentialType</label><br/>
                <select id="HashCredentialType" name="HashCredentialType" asp-items="Html.GetEnumSelectList<HashType>()" class="selectpicker show-menu-arrow" data-dropup-auto="false" data-width="auto"></select>
            </div>
            <div class="form-group col-md-9">
                <label for="Hash">Hash</label>
                <input id="Hash" name="Hash" class="form-control" disabled>
            </div>
        </div>
    </div>
    <div id="ticket-section" hidden>
        <div class="form-row">
            <div class="form-group col-md-3">
                <label for="TicketCredentialType">TicketCredentialType</label><br/>
                <select id="TicketCredentialType" name="TicketCredentialType" asp-items="Html.GetEnumSelectList<TicketType>()" class="selectpicker show-menu-arrow" data-dropup-auto="false" data-width="auto"></select>
            </div>
            <div class="form-group col-md-9">
                <label for="ServiceName">ServiceName</label>
                <input id="ServiceName" name="ServiceName" class="form-control" disabled>
            </div>
        </div>
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="Ticket">Ticket</label>
                <input id="Ticket" name="Ticket" class="form-control" disabled>
            </div>
        </div>
    </div>
    <button type="submit" class="btn btn-primary"><span data-feather="plus"></span> Create</button>
</form>

@section Scripts
{
    <script type="text/javascript">
        $(document).ready(function() {
            function swapType(){
                var type = $(this).children("option:selected").val();
                if (type == 0)
                {
                    $("#password-section").attr("hidden", false);
                    $("#password-section").find("input").prop("disabled", false);

                    $("#hash-section").attr("hidden", true);
                    $("#hash-section").find("input").prop("disabled", true);

                    $("#ticket-section").attr("hidden", true);
                    $("#ticket-section").find("input").prop("disabled", true);

                    $("form").attr("action", "/credential/createpasswordcredential");
                }
                else if (type == 1)
                {
                    $("#password-section").attr("hidden", true);
                    $("#password-section").find("input").prop("disabled", true);

                    $("#hash-section").attr("hidden", false);
                    $("#hash-section").find("input").prop("disabled", false);

                    $("#ticket-section").attr("hidden", true);
                    $("#ticket-section").find("input").prop("disabled", true);

                    $("form").attr("action", "/credential/createhashcredential");
                }
                else if (type == 2)
                {
                    $("#password-section").attr("hidden", true);
                    $("#password-section").find("input").prop("disabled", true);

                    $("#hash-section").attr("hidden", true);
                    $("#hash-section").find("input").prop("disabled", true);

                    $("#ticket-section").attr("hidden", false);
                    $("#ticket-section").find("input").prop("disabled", false);

                    $("form").attr("action", "/credential/createticketcredential");
                }
            };
            $("#Type").change(swapType);
            swapType();
        });
    </script>
}